<?php
/**
 * 公告通知
 */
namespace app\admin\controller;

use app\common\model\Notice as Ni;
class NotsController extends BaseController{
	public function lst(){
		$this->assign([
			'data'=>Ni::paginate(7)
		]);
		return $this->fetch();
	}
	//添加公告通知
	
	public function add(){
		if($this->request->isPost() ){
			$params=$this->request->except('/admin/nots/add');
			if((new Ni($params) )->allowField(true)->save() ){
				$this->success('添加公共通告成功
					!','lst','',1);
			}else{
				$this->error('添加公共通告失败!','add','',1);
			}
			return;
		}
		return $this->fetch();
	}
	//删除公告通知
	public function  del(){
		$i=$this->request->param('id');
		if(Ni::destroy($i) ){
			return '删除成功!';
		}else{
			return '删除失败!';
		}
	}
	//修改公共通告
	public function edi(){
		$i=$this->request->param('id');
		if($this->request->isGet() ){
			$this->assign([
				'nots'=>Ni::find($i)
			]);
			return $this->fetch();
		}
		if($this->request->isPost() ){
			$data=$this->request->except('id');
			if((new Ni())->allowField(true)->save($data,['id'=>$i]) ){
				$this->success('修改成功','lst','',1);
			}else{
				$this->redirect('/admin/nots/edi/id/'.$i);
			}
		}
	}
}